﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SaludOcupacional.Model;
using SaludOcupacional.Controller;

namespace SaludOcupacional
{
    /// <summary>
    /// Interaction logic for Analisis.xaml
    /// </summary>
    public partial class Analisis : Window
    {

        private Empleado Empleado;
        public Analisis(Empleado empleado)
        {
            InitializeComponent();
            Empleado = empleado;
            nombre.Content = empleado.Nombre + " " + empleado.ApellidoPaterno + " " + empleado.ApellidoMaterno;
            codigo.Content = empleado.Codigo;
            fecha.Text = DateTime.Now.ToString();



            //Respiratorio
            Respiratorio respiratorio = RespiratorioManager.BuscarAnalisisPorCi(Empleado.Ci);
            if (respiratorio == null)
            {
                vRespiratorioRadiografia.Visibility = Visibility.Hidden;
                vRespiratorioObstructiva.Visibility = Visibility.Hidden;
                vRespiratorioRestrictiva.Visibility = Visibility.Hidden;
                vRespiratorioNotas.Visibility = Visibility.Hidden;
                vRespiratorioAccion.Visibility = Visibility.Hidden;
                vRespiratorioObservaciones.Visibility = Visibility.Hidden;
            }
            else 
            {
                rRespiratorioRadiografia.Text = respiratorio.Radiografia;
                rRespiratorioObstructiva.Text = respiratorio.Obstructiva;
                rRespiratorioRestrictiva.Text = respiratorio.Restrictiva;
                rRespiratorioNotas.Text = respiratorio.Nota;
                rRespiratorioAccion.Text = respiratorio.Accion;
                rRespiratorioObservaciones.Text = respiratorio.Observaciones;


                vRespiratorioRadiografia.Visibility = Visibility.Visible;
                vRespiratorioObstructiva.Visibility = Visibility.Visible;
                vRespiratorioRestrictiva.Visibility = Visibility.Visible;
                vRespiratorioNotas.Visibility = Visibility.Visible;
                vRespiratorioAccion.Visibility = Visibility.Visible;
                vRespiratorioAccion.Visibility = Visibility.Visible;
                vRespiratorioObservaciones.Visibility = Visibility.Visible;

                vRespiratorioRadiografia.Content = respiratorio.Radiografia;
                vRespiratorioObstructiva.Content = respiratorio.Obstructiva;
                vRespiratorioRestrictiva.Content = respiratorio.Restrictiva;
                vRespiratorioNotas.Text = respiratorio.Nota;
                vRespiratorioAccion.Content = respiratorio.Accion;
                vRespiratorioObservaciones.Text = respiratorio.Observaciones;
            }

            //Audiometrico
            Audiometrico audimetrico = AudiometricoManager.BuscarAnalisisPorCi(Empleado.Ci);
            if (audimetrico == null)
            {
                vAudiometricoIzq.Visibility = Visibility.Hidden;
                vAudiometricoDere.Visibility = Visibility.Hidden;
                vAudiometricoBilateral.Visibility = Visibility.Hidden;
                vAudiometricoAcciones.Visibility = Visibility.Hidden;
                vAudiometricoObservaciones.Visibility = Visibility.Hidden;

            }
            else
            {
                rAudiometricoIzq.Text = audimetrico.Izq;
                rAudiometricoDere.Text = audimetrico.Der;
                rAudiometricoBilateral.Text = audimetrico.Bilateral;
                rAudiometricoAcciones.Text = audimetrico.Acciones;
                rAudiometricoObservaciones.Text = audimetrico.Observaciones;



                vAudiometricoIzq.Visibility = Visibility.Visible;
                vAudiometricoDere.Visibility = Visibility.Visible;
                vAudiometricoBilateral.Visibility = Visibility.Visible;
                vAudiometricoAcciones.Visibility = Visibility.Visible;
                vAudiometricoObservaciones.Visibility = Visibility.Visible;

                vAudiometricoIzq.Content = audimetrico.Izq;
                vAudiometricoDere.Content = audimetrico.Der;
                vAudiometricoBilateral.Content = audimetrico.Bilateral;
                vAudiometricoAcciones.Content = audimetrico.Acciones;
                vAudiometricoObservaciones.Text = audimetrico.Observaciones;
            }

            //Oftalmologico
            Oftalmologico oft = OftalmologicoManager.BuscarAnalisisPorCi(Empleado.Ci);
            if (oft == null)
            {
                vOftalmologicoOiSin.Visibility = Visibility.Hidden;
                vOftalmologicoOdSin.Visibility = Visibility.Hidden;
                vOftalmologicoOiCon.Visibility = Visibility.Hidden;
                vOftalmologicoOdCon.Visibility = Visibility.Hidden;
                vOftalmologicoUsoLentes.Visibility = Visibility.Hidden;
                vOftalmologicoAcciones.Visibility = Visibility.Hidden;
                vOftalmologicoMiopia.Visibility = Visibility.Hidden;
                vOftalmologicoAstig.Visibility = Visibility.Hidden;
                vOftalmologicoHiper.Visibility = Visibility.Hidden;
                vOftalmologicoPter.Visibility = Visibility.Hidden;
                vOftalmologicoPingue.Visibility = Visibility.Hidden;
                vOftalmologicoSeudo.Visibility = Visibility.Hidden;
                vOftalmologicoDalton.Visibility = Visibility.Hidden;
                vOftalmologicoNorm.Visibility = Visibility.Hidden;
                vOftalmologicoObservaciones.Visibility = Visibility.Hidden;


            }
            else
            {
                rOftalmologicoOiSin.Text = oft.OiSin;
                rOftalmologicoOdSin.Text = oft.OdSin;
                rOftalmologicoOiCon.Text = oft.OiCon;
                rOftalmologicoOdCon.Text = oft.OdCon;
                rOftalmologicoLentes.Text = oft.UsoLentes;
                rOftalmologicoAcciones.Text = oft.Accion;
                rOftalmologicoMiopia.Text = oft.Miopia;
                rOftalmologicoAstigm.Text = oft.Astigmatismo;
                rOftalmologicoHiperm.Text = oft.Hipermetropia;
                rOftalmologicoPteri.Text = oft.Pterigiun;
                rOftalmologicoPingue.Text = oft.Pinguecula;
                rOftalmologicoSeudof.Text = oft.Seudofaquia;
                rOftalmologicoDaltonismo.Text = oft.Daltonismo;
                rOftalmologicoNorm.Text = oft.Normal;
                rOftalmologicoObservaciones.Text = oft.Observaciones;


                vOftalmologicoOiSin.Visibility = Visibility.Visible;
                vOftalmologicoOdSin.Visibility = Visibility.Visible;
                vOftalmologicoOiCon.Visibility = Visibility.Visible;
                vOftalmologicoOdCon.Visibility = Visibility.Visible;
                vOftalmologicoUsoLentes.Visibility = Visibility.Visible;
                vOftalmologicoAcciones.Visibility = Visibility.Visible;
                vOftalmologicoMiopia.Visibility = Visibility.Visible;
                vOftalmologicoAstig.Visibility = Visibility.Visible;
                vOftalmologicoHiper.Visibility = Visibility.Visible;
                vOftalmologicoPter.Visibility = Visibility.Visible;
                vOftalmologicoPingue.Visibility = Visibility.Visible;
                vOftalmologicoSeudo.Visibility = Visibility.Visible;
                vOftalmologicoDalton.Visibility = Visibility.Visible;
                vOftalmologicoNorm.Visibility = Visibility.Visible;
                vOftalmologicoObservaciones.Visibility = Visibility.Visible;

                vOftalmologicoOiSin.Content = oft.OiSin;
                vOftalmologicoOdSin.Content = oft.OdSin;
                vOftalmologicoOiCon.Content = oft.OiCon;
                vOftalmologicoOdCon.Content = oft.OdCon;
                vOftalmologicoUsoLentes.Content = oft.UsoLentes;
                vOftalmologicoAcciones.Content = oft.Accion;
                vOftalmologicoMiopia.Content = oft.Miopia;
                vOftalmologicoAstig.Content = oft.Astigmatismo;
                vOftalmologicoHiper.Content = oft.Hipermetropia;
                vOftalmologicoPter.Content = oft.Pterigiun;
                vOftalmologicoPingue.Content = oft.Pinguecula;
                vOftalmologicoSeudo.Content = oft.Seudofaquia;
                vOftalmologicoDalton.Content = oft.Daltonismo;
                vOftalmologicoNorm.Content = oft.Normal;
                vOftalmologicoObservaciones.Text = oft.Observaciones;

            }

            //Laboratorial
            Laboratorial labo = LaboratorialManager.BuscarAnalisisPorCi(Empleado.Ci);
            if (labo == null)
            {
                vLaboratorioWidal.Visibility = Visibility.Hidden;
                vLaboratorioChagas.Visibility = Visibility.Hidden;
                vLaboratorioDiabetes.Visibility = Visibility.Hidden;
                vLaboratorioHepatitis.Visibility = Visibility.Hidden;
                vLaboratorioVih.Visibility = Visibility.Hidden;
                vLaboratorioPlomo.Visibility = Visibility.Hidden;
                vLaboratorioXileno.Visibility = Visibility.Hidden;
                vLaboratorioTolueno.Visibility = Visibility.Hidden;
                vLaboratorioOrina.Visibility = Visibility.Hidden;
                vLaboratorioHb.Visibility = Visibility.Hidden;
                vLaboratorioHto.Visibility = Visibility.Hidden;
                vLaboratorioColesterol.Visibility = Visibility.Hidden;
                vLaboratorioVdrl.Visibility = Visibility.Hidden;
                vLaboratorioAcido.Visibility = Visibility.Hidden;
                vLaboratorioGlicemia.Visibility = Visibility.Hidden;
                vLaboratorioTrigiceridos.Visibility = Visibility.Hidden;
                vLaboratorioCreatina.Visibility = Visibility.Hidden;
                vLaboratorioObservaciones.Visibility = Visibility.Hidden;
                vLaboratorioAcciones.Visibility = Visibility.Hidden;


            }
            else
            {
                rLaboratorioWidal.Text = labo.Widal;
                rLaboratorioChagas.Text = labo.Chagas;
                rLaboratorioDiabetes.Text = labo.Diabetes;
                rLaboratorioHepatitis.Text = labo.Hepatitis;
                rLaboratorioVih.Text = labo.Vih;
                rLaboratorioPlomo.Text = labo.Plomo.ToString();
                rLaboratorioXileno.Text = labo.Xileno.ToString();
                rLaboratorioTolueno.Text = labo.Tolueno.ToString();
                rLaboratorioOrina.Text = labo.Orina;
                rLaboratorioHb.Text = labo.Hb.ToString();
                rLaboratorioHto.Text = labo.Hto.ToString();
                rLaboratorioColesterol.Text = labo.Colesterol.ToString();
                rLaboratorioVdrl.Text = labo.Vdrl;
                rLaboratorioAcidoUrico.Text = labo.AcidoUrico.ToString();
                rLaboratorioGlicemia.Text = labo.Glicemia.ToString();
                rLaboratorioTrigliceridos.Text = labo.Trigliceridos.ToString();
                rLaboratorioCreatinina.Text = labo.Creatina.ToString();
                rLaboratorioObservaciones.Text = labo.Observaciones;
                rLaboratorioAcciones.Text = labo.Accion;


                vLaboratorioWidal.Visibility = Visibility.Visible;
                vLaboratorioChagas.Visibility = Visibility.Visible;
                vLaboratorioDiabetes.Visibility = Visibility.Visible;
                vLaboratorioHepatitis.Visibility = Visibility.Visible;
                vLaboratorioVih.Visibility = Visibility.Visible;
                vLaboratorioPlomo.Visibility = Visibility.Visible;
                vLaboratorioXileno.Visibility = Visibility.Visible;
                vLaboratorioTolueno.Visibility = Visibility.Visible;
                vLaboratorioOrina.Visibility = Visibility.Visible;
                vLaboratorioHb.Visibility = Visibility.Visible;
                vLaboratorioHto.Visibility = Visibility.Visible;
                vLaboratorioColesterol.Visibility = Visibility.Visible;
                vLaboratorioVdrl.Visibility = Visibility.Visible;
                vLaboratorioAcido.Visibility = Visibility.Visible;
                vLaboratorioGlicemia.Visibility = Visibility.Visible;
                vLaboratorioTrigiceridos.Visibility = Visibility.Visible;
                vLaboratorioCreatina.Visibility = Visibility.Visible;
                vLaboratorioObservaciones.Visibility = Visibility.Visible;
                vLaboratorioAcciones.Visibility = Visibility.Visible;

                vLaboratorioWidal.Content = labo.Widal;
                vLaboratorioChagas.Content = labo.Chagas;
                vLaboratorioDiabetes.Content = labo.Diabetes;
                vLaboratorioHepatitis.Content = labo.Hepatitis;
                vLaboratorioVih.Content = labo.Vih;
                vLaboratorioPlomo.Content = labo.Plomo;
                vLaboratorioXileno.Content = labo.Xileno;
                vLaboratorioTolueno.Content = labo.Tolueno;
                vLaboratorioOrina.Content = labo.Orina;
                vLaboratorioHb.Content = labo.Hb;
                vLaboratorioHto.Content = labo.Hto;
                vLaboratorioColesterol.Content = labo.Colesterol;
                vLaboratorioVdrl.Content = labo.Vdrl;
                vLaboratorioAcido.Content = labo.AcidoUrico;
                vLaboratorioGlicemia.Content = labo.Glicemia;
                vLaboratorioTrigiceridos.Content = labo.Trigliceridos;
                vLaboratorioCreatina.Content = labo.Creatina;
                vLaboratorioObservaciones.Text = labo.Observaciones;
                vLaboratorioAcciones.Content = labo.Accion;

            }

            //Carnet Sanitario
            Carnet carnet = CarnetManager.BuscarAnalisisPorCi(Empleado.Ci);
            if (carnet == null)
            {
     
                vCarnetAscaris.Visibility = Visibility.Hidden;
                vCarnetAmebas.Visibility = Visibility.Hidden;
                vCarnetGiardias.Visibility = Visibility.Hidden;
                vCarnetNematodos.Visibility = Visibility.Hidden;
                vCarnetTrematodos.Visibility = Visibility.Hidden;
                vCarnetTrichuris.Visibility = Visibility.Hidden;
                vCarnetOtros.Visibility = Visibility.Hidden;

                vCarnetObservaciones.Visibility = Visibility.Hidden;
                vCarnetAcciones.Visibility = Visibility.Hidden;


            }
            else
            {
       
                rCarnetAscaris.Text = carnet.Ascaris;
                rCarnetAmebas.Text = carnet.Amebas;
                rCarnetGiardias.Text = carnet.Giardias;
                rCarnetNematodos.Text = carnet.Nematodos;
                rCarnetTrematodos.Text = carnet.Trematodos;
                rCarnetTrichuris.Text = carnet.Trichuris;
                rCarnetOtros.Text = carnet.OtrosParasitos;

                rCarnetObservaciones.Text = carnet.Observaciones;
                rCarnetAcciones.Text = carnet.Acciones;


            
                vCarnetAscaris.Visibility = Visibility.Visible;
                vCarnetAmebas.Visibility = Visibility.Visible;
                vCarnetGiardias.Visibility = Visibility.Visible;
                vCarnetNematodos.Visibility = Visibility.Visible;
                vCarnetTrematodos.Visibility = Visibility.Visible;
                vCarnetTrichuris.Visibility = Visibility.Visible;
                vCarnetOtros.Visibility = Visibility.Visible;

                vCarnetObservaciones.Visibility = Visibility.Visible;
                vCarnetAcciones.Visibility = Visibility.Visible;

                vCarnetAscaris.Content = carnet.Ascaris;
                vCarnetAmebas.Content = carnet.Amebas;
                vCarnetGiardias.Content = carnet.Giardias;
                vCarnetNematodos.Content = carnet.Nematodos;
                vCarnetTrematodos.Content = carnet.Trematodos;
                vCarnetTrichuris.Content = carnet.Trichuris;
                vCarnetOtros.Content = carnet.OtrosParasitos;

                vCarnetObservaciones.Text = carnet.Observaciones;
                vCarnetAcciones.Content = carnet.Acciones;

            }
     
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

       

        private void button14_Click(object sender, RoutedEventArgs e)
        {
            tabCOntrol.Visibility = Visibility.Visible;
            

            rRespiratorio.Visibility = Visibility.Visible;
            eRespiratorio.Visibility = Visibility.Visible;
            rRespiratorio2.Visibility = Visibility.Visible;
            eRespiratorio2.Visibility = Visibility.Visible;

            vAudiometrico.Visibility = Visibility.Hidden;
            rAudiometrico.Visibility = Visibility.Hidden;
            vAudiometrico2.Visibility = Visibility.Hidden;
            rAudiometrico2.Visibility = Visibility.Hidden;

            vOftalmologico.Visibility = Visibility.Hidden;
            rOftalmologico.Visibility = Visibility.Hidden;
            vOftalmologico2.Visibility = Visibility.Hidden;
            rOftalmologico2.Visibility = Visibility.Hidden;

            vLaboratorio.Visibility = Visibility.Hidden;
            vLaboratorio2.Visibility = Visibility.Hidden;
            rLaboratorio.Visibility = Visibility.Hidden;
            rLaboratorio2.Visibility = Visibility.Hidden;

            vCarnet.Visibility = Visibility.Hidden;
            vCarnet2.Visibility = Visibility.Hidden;
            rCarnet.Visibility = Visibility.Hidden;
            rCarnet2.Visibility = Visibility.Hidden;

        }

        private void button15_Click(object sender, RoutedEventArgs e)
        {
            tabCOntrol.Visibility = Visibility.Visible;
            

            rRespiratorio.Visibility = Visibility.Hidden;
            eRespiratorio.Visibility = Visibility.Hidden;
            rRespiratorio2.Visibility = Visibility.Hidden;
            eRespiratorio2.Visibility = Visibility.Hidden;
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                Respiratorio respiratorio = RespiratorioManager.BuscarAnalisisPorCi(Empleado.Ci);
                if (respiratorio == null)
                {
                    Respiratorio resp = new Respiratorio(0, Empleado.Ci, rRespiratorioRadiografia.Text, rRespiratorioObstructiva.Text, rRespiratorioRestrictiva.Text, rRespiratorioNotas.Text, rRespiratorioAccion.Text, rRespiratorioObservaciones.Text, fecha.Text);
                    RespiratorioManager.RegistrarAnalisis(resp);
                    MessageBox.Show("ANALISIS REGISTRADO!");


                }
                else
                {
                    Respiratorio resp = new Respiratorio(0, Empleado.Ci, rRespiratorioRadiografia.Text, rRespiratorioObstructiva.Text, rRespiratorioRestrictiva.Text, rRespiratorioNotas.Text, rRespiratorioAccion.Text, rRespiratorioObservaciones.Text, fecha.Text);
                    RespiratorioManager.EditarAnalisis(resp);
                    MessageBox.Show("ANALISIS MODIFICADO!");
                }


                vRespiratorioRadiografia.Visibility = Visibility.Visible;
                vRespiratorioObstructiva.Visibility = Visibility.Visible;
                vRespiratorioRestrictiva.Visibility = Visibility.Visible;
                vRespiratorioNotas.Visibility = Visibility.Visible;
                vRespiratorioAccion.Visibility = Visibility.Visible;
                vRespiratorioAccion.Visibility = Visibility.Visible;
                vRespiratorioObservaciones.Visibility = Visibility.Visible;

                Respiratorio respiratorio2 = RespiratorioManager.BuscarAnalisisPorCi(Empleado.Ci);
                vRespiratorioRadiografia.Content = respiratorio2.Radiografia;
                vRespiratorioObstructiva.Content = respiratorio2.Obstructiva;
                vRespiratorioRestrictiva.Content = respiratorio2.Restrictiva;
                vRespiratorioNotas.Text = respiratorio2.Nota;
                vRespiratorioAccion.Content = respiratorio2.Accion;
                vRespiratorioObservaciones.Text = respiratorio2.Observaciones;
            }
            catch (Exception ex)
            {

                MessageBox.Show("Error: " + ex.Message);
            }
        }

        private void button8_Click(object sender, RoutedEventArgs e)
        {
            tabCOntrol.Visibility = Visibility.Visible;


            rRespiratorio.Visibility = Visibility.Hidden;
            eRespiratorio.Visibility = Visibility.Hidden;
            rRespiratorio2.Visibility = Visibility.Hidden;
            eRespiratorio2.Visibility = Visibility.Hidden;

            vAudiometrico.Visibility = Visibility.Visible;
            rAudiometrico.Visibility = Visibility.Visible;
            vAudiometrico2.Visibility = Visibility.Visible;
            rAudiometrico2.Visibility = Visibility.Visible;

            vOftalmologico.Visibility = Visibility.Hidden;
            rOftalmologico.Visibility = Visibility.Hidden;
            vOftalmologico2.Visibility = Visibility.Hidden;
            rOftalmologico2.Visibility = Visibility.Hidden;

            vLaboratorio.Visibility = Visibility.Hidden;
            vLaboratorio2.Visibility = Visibility.Hidden;
            rLaboratorio.Visibility = Visibility.Hidden;
            rLaboratorio2.Visibility = Visibility.Hidden;

            vCarnet.Visibility = Visibility.Hidden;
            vCarnet2.Visibility = Visibility.Hidden;
            rCarnet.Visibility = Visibility.Hidden;
            rCarnet2.Visibility = Visibility.Hidden;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                Audiometrico audiometrico = AudiometricoManager.BuscarAnalisisPorCi(Empleado.Ci);
                if (audiometrico == null)
                {
                    Audiometrico resp = new Audiometrico(0, Empleado.Ci, rAudiometricoIzq.Text, rAudiometricoDere.Text, rAudiometricoBilateral.Text, rAudiometricoAcciones.Text, rAudiometricoObservaciones.Text, fecha.Text);
                    AudiometricoManager.RegistrarAnalisis(resp);
                    MessageBox.Show("ANALISIS REGISTRADO!");


                }
                else
                {
                    Audiometrico resp = new Audiometrico(0, Empleado.Ci, rAudiometricoIzq.Text, rAudiometricoDere.Text, rAudiometricoBilateral.Text, rAudiometricoAcciones.Text, rAudiometricoObservaciones.Text, fecha.Text);
                    AudiometricoManager.EditarAnalisis(resp);
                    MessageBox.Show("ANALISIS MODIFICADO!");
                }


                vAudiometricoIzq.Visibility = Visibility.Visible;
                vAudiometricoDere.Visibility = Visibility.Visible;
                vAudiometricoBilateral.Visibility = Visibility.Visible;
                vAudiometricoAcciones.Visibility = Visibility.Visible;
                vAudiometricoObservaciones.Visibility = Visibility.Visible;

                Audiometrico audiometrico2 = AudiometricoManager.BuscarAnalisisPorCi(Empleado.Ci);
                vAudiometricoIzq.Content = audiometrico2.Izq;
                vAudiometricoDere.Content = audiometrico2.Der;
                vAudiometricoBilateral.Content = audiometrico2.Bilateral;
                vAudiometricoAcciones.Content = audiometrico2.Acciones;
                vAudiometricoObservaciones.Text = audiometrico2.Observaciones;
            }
            catch (Exception ex)
            {

                MessageBox.Show("Error: " + ex.Message);
            }
        }

        private void button11_Click(object sender, RoutedEventArgs e)
        {

            tabCOntrol.Visibility = Visibility.Visible;

            vOftalmologico.Visibility = Visibility.Visible;
            rOftalmologico.Visibility = Visibility.Visible;
            vOftalmologico2.Visibility = Visibility.Visible;
            rOftalmologico2.Visibility = Visibility.Visible;

            rRespiratorio.Visibility = Visibility.Hidden;
            eRespiratorio.Visibility = Visibility.Hidden;
            rRespiratorio2.Visibility = Visibility.Hidden;
            eRespiratorio2.Visibility = Visibility.Hidden;

            vAudiometrico.Visibility = Visibility.Hidden;
            rAudiometrico.Visibility = Visibility.Hidden;
            vAudiometrico2.Visibility = Visibility.Hidden;
            rAudiometrico2.Visibility = Visibility.Hidden;

            vLaboratorio.Visibility = Visibility.Hidden;
            vLaboratorio2.Visibility = Visibility.Hidden;
            rLaboratorio.Visibility = Visibility.Hidden;
            rLaboratorio2.Visibility = Visibility.Hidden;

            vCarnet.Visibility = Visibility.Hidden;
            vCarnet2.Visibility = Visibility.Hidden;
            rCarnet.Visibility = Visibility.Hidden;
            rCarnet2.Visibility = Visibility.Hidden;
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                Oftalmologico oftal = OftalmologicoManager.BuscarAnalisisPorCi(Empleado.Ci);
                if (oftal == null)
                {
                    Oftalmologico resp = new Oftalmologico(0, Empleado.Ci, rOftalmologicoLentes.Text, rOftalmologicoOiSin.Text, rOftalmologicoOdSin.Text, rOftalmologicoOiCon.Text, rOftalmologicoOdCon.Text, rOftalmologicoMiopia.Text, rOftalmologicoAstigm.Text, rOftalmologicoHiperm.Text, rOftalmologicoPteri.Text, rOftalmologicoPingue.Text, rOftalmologicoSeudof.Text, rOftalmologicoDaltonismo.Text, rOftalmologicoNorm.Text, rOftalmologicoAcciones.Text, rOftalmologicoObservaciones.Text, fecha.Text);
                    OftalmologicoManager.RegistrarAnalisis(resp);
                    MessageBox.Show("ANALISIS REGISTRADO!");


                }
                else
                {
                    Oftalmologico resp = new Oftalmologico(0, Empleado.Ci, rOftalmologicoLentes.Text, rOftalmologicoOiSin.Text, rOftalmologicoOdSin.Text, rOftalmologicoOiCon.Text, rOftalmologicoOdCon.Text, rOftalmologicoMiopia.Text, rOftalmologicoAstigm.Text, rOftalmologicoHiperm.Text, rOftalmologicoPteri.Text, rOftalmologicoPingue.Text, rOftalmologicoSeudof.Text, rOftalmologicoDaltonismo.Text, rOftalmologicoNorm.Text, rOftalmologicoAcciones.Text, rOftalmologicoObservaciones.Text, fecha.Text);
                    OftalmologicoManager.EditarAnalisis(resp);
                    MessageBox.Show("ANALISIS MODIFICADO!");
                }


                vOftalmologicoOiSin.Visibility = Visibility.Visible;
                vOftalmologicoOdSin.Visibility = Visibility.Visible;
                vOftalmologicoOiCon.Visibility = Visibility.Visible;
                vOftalmologicoOdCon.Visibility = Visibility.Visible;
                vOftalmologicoUsoLentes.Visibility = Visibility.Visible;
                vOftalmologicoAcciones.Visibility = Visibility.Visible;
                vOftalmologicoMiopia.Visibility = Visibility.Visible;
                vOftalmologicoAstig.Visibility = Visibility.Visible;
                vOftalmologicoHiper.Visibility = Visibility.Visible;
                vOftalmologicoPter.Visibility = Visibility.Visible;
                vOftalmologicoPingue.Visibility = Visibility.Visible;
                vOftalmologicoSeudo.Visibility = Visibility.Visible;
                vOftalmologicoDalton.Visibility = Visibility.Visible;
                vOftalmologicoNorm.Visibility = Visibility.Visible;
                vOftalmologicoObservaciones.Visibility = Visibility.Visible;

                Oftalmologico oft = OftalmologicoManager.BuscarAnalisisPorCi(Empleado.Ci);
                vOftalmologicoOiSin.Content = oft.OiSin;
                vOftalmologicoOdSin.Content = oft.OdSin;
                vOftalmologicoOiCon.Content = oft.OiCon;
                vOftalmologicoOdCon.Content = oft.OdCon;
                vOftalmologicoUsoLentes.Content = oft.UsoLentes;
                vOftalmologicoAcciones.Content = oft.Accion;
                vOftalmologicoMiopia.Content = oft.Miopia;
                vOftalmologicoAstig.Content = oft.Astigmatismo;
                vOftalmologicoHiper.Content = oft.Hipermetropia;
                vOftalmologicoPter.Content = oft.Pterigiun;
                vOftalmologicoPingue.Content = oft.Pinguecula;
                vOftalmologicoSeudo.Content = oft.Seudofaquia;
                vOftalmologicoDalton.Content = oft.Daltonismo;
                vOftalmologicoNorm.Content = oft.Normal;
                vOftalmologicoObservaciones.Text = oft.Observaciones;
            }
            catch (Exception ex)
            {

                MessageBox.Show("Error: " + ex.Message);
            }
        }

        private void button16_Click(object sender, RoutedEventArgs e)
        {
            tabCOntrol.Visibility = Visibility.Visible;


            rRespiratorio.Visibility = Visibility.Hidden;
            eRespiratorio.Visibility = Visibility.Hidden;
            rRespiratorio2.Visibility = Visibility.Hidden;
            eRespiratorio2.Visibility = Visibility.Hidden;

            vAudiometrico.Visibility = Visibility.Hidden;
            rAudiometrico.Visibility = Visibility.Hidden;
            vAudiometrico2.Visibility = Visibility.Hidden;
            rAudiometrico2.Visibility = Visibility.Hidden;

            vOftalmologico.Visibility = Visibility.Hidden;
            rOftalmologico.Visibility = Visibility.Hidden;
            vOftalmologico2.Visibility = Visibility.Hidden;
            rOftalmologico2.Visibility = Visibility.Hidden;

            vLaboratorio.Visibility = Visibility.Visible;
            vLaboratorio2.Visibility = Visibility.Visible;
            rLaboratorio.Visibility = Visibility.Visible;
            rLaboratorio2.Visibility = Visibility.Visible;

            vCarnet.Visibility = Visibility.Hidden;
            vCarnet2.Visibility = Visibility.Hidden;
            rCarnet.Visibility = Visibility.Hidden;
            rCarnet2.Visibility = Visibility.Hidden;
        }

        private void button5_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                float plomo = 0;
                float xileno = 0;
                float tolueno = 0;
                float hb = 0;
                float hto = 0;
                float colesterol = 0;
                float acido = 0;
                float glicemia = 0;
                float trigliceridos = 0;
                float creatina = 0;

                if (rLaboratorioPlomo.Text == "")
                    plomo = 0;
                else
                    plomo = Convert.ToInt64(rLaboratorioPlomo.Text);
                if (rLaboratorioXileno.Text == "")
                    xileno = 0;
                else
                    xileno = Convert.ToInt64(rLaboratorioXileno.Text);
                if (rLaboratorioTolueno.Text == "")
                    tolueno = 0;
                else
                    tolueno = Convert.ToInt64(rLaboratorioTolueno.Text);
                if (rLaboratorioHb.Text == "")
                    hb = 0;
                else
                    hb = Convert.ToInt64(rLaboratorioHb.Text);
                if (rLaboratorioHto.Text == "")
                    hto = 0;
                else
                    hto = Convert.ToInt64(rLaboratorioHto.Text);
                if (rLaboratorioColesterol.Text == "")
                    colesterol = 0;
                else
                    colesterol = Convert.ToInt64(rLaboratorioColesterol.Text);
                if (rLaboratorioAcidoUrico.Text == "")
                    acido = 0;
                else
                    acido = Convert.ToInt64(rLaboratorioAcidoUrico.Text);
                if (rLaboratorioGlicemia.Text == "")
                    glicemia = 0;
                else
                    glicemia = Convert.ToInt32(rLaboratorioGlicemia.Text);
                if (rLaboratorioTrigliceridos.Text == "")
                    trigliceridos = 0;
                else
                    trigliceridos = Convert.ToInt32(rLaboratorioTrigliceridos.Text);
                if (rLaboratorioCreatinina.Text == "")
                    creatina = 0;
                else
                    creatina = Convert.ToInt32(rLaboratorioCreatinina.Text);

                Laboratorial labo = LaboratorialManager.BuscarAnalisisPorCi(Empleado.Ci);
                if (labo == null)
                {
                    Laboratorial resp = new Laboratorial(0, Empleado.Ci, rLaboratorioWidal.Text, rLaboratorioChagas.Text, rLaboratorioDiabetes.Text, rLaboratorioHepatitis.Text, rLaboratorioVih.Text, plomo, xileno, tolueno, rLaboratorioOrina.Text, hb, hto, glicemia, colesterol, trigliceridos, acido, rLaboratorioVdrl.Text, creatina, rLaboratorioObservaciones.Text, rLaboratorioAcciones.Text, fecha.Text);
                    LaboratorialManager.RegistrarAnalisis(resp);
                    MessageBox.Show("ANALISIS REGISTRADO!");


                }
                else
                {
                    Laboratorial resp = new Laboratorial(0, Empleado.Ci, rLaboratorioWidal.Text, rLaboratorioChagas.Text, rLaboratorioDiabetes.Text, rLaboratorioHepatitis.Text, rLaboratorioVih.Text, plomo, xileno, tolueno, rLaboratorioOrina.Text, hb, hto, glicemia, colesterol, trigliceridos, acido, rLaboratorioVdrl.Text, creatina, rLaboratorioObservaciones.Text, rLaboratorioAcciones.Text, fecha.Text);
                    LaboratorialManager.EditarAnalisis(resp);
                    MessageBox.Show("ANALISIS MODIFICADO!");
                }


                vLaboratorioWidal.Visibility = Visibility.Visible;
                vLaboratorioChagas.Visibility = Visibility.Visible;
                vLaboratorioDiabetes.Visibility = Visibility.Visible;
                vLaboratorioHepatitis.Visibility = Visibility.Visible;
                vLaboratorioVih.Visibility = Visibility.Visible;
                vLaboratorioPlomo.Visibility = Visibility.Visible;
                vLaboratorioXileno.Visibility = Visibility.Visible;
                vLaboratorioTolueno.Visibility = Visibility.Visible;
                vLaboratorioOrina.Visibility = Visibility.Visible;
                vLaboratorioHb.Visibility = Visibility.Visible;
                vLaboratorioHto.Visibility = Visibility.Visible;
                vLaboratorioColesterol.Visibility = Visibility.Visible;
                vLaboratorioVdrl.Visibility = Visibility.Visible;
                vLaboratorioAcido.Visibility = Visibility.Visible;
                vLaboratorioGlicemia.Visibility = Visibility.Visible;
                vLaboratorioTrigiceridos.Visibility = Visibility.Visible;
                vLaboratorioCreatina.Visibility = Visibility.Visible;
                vLaboratorioObservaciones.Visibility = Visibility.Visible;
                vLaboratorioAcciones.Visibility = Visibility.Visible;

                Laboratorial lab = LaboratorialManager.BuscarAnalisisPorCi(Empleado.Ci);
                vLaboratorioWidal.Content = lab.Widal;
                vLaboratorioChagas.Content = lab.Chagas;
                vLaboratorioDiabetes.Content = lab.Diabetes;
                vLaboratorioHepatitis.Content = lab.Hepatitis;
                vLaboratorioVih.Content = lab.Vih;
                vLaboratorioPlomo.Content = lab.Plomo;
                vLaboratorioXileno.Content = lab.Xileno;
                vLaboratorioTolueno.Content = lab.Tolueno;
                vLaboratorioOrina.Content = lab.Orina;
                vLaboratorioHb.Content = lab.Hb;
                vLaboratorioHto.Content = lab.Hto;
                vLaboratorioColesterol.Content = lab.Colesterol;
                vLaboratorioVdrl.Content = lab.Vdrl;
                vLaboratorioAcido.Content = lab.AcidoUrico;
                vLaboratorioGlicemia.Content = lab.Glicemia;
                vLaboratorioTrigiceridos.Content = lab.Trigliceridos;
                vLaboratorioCreatina.Content = lab.Creatina;
                vLaboratorioObservaciones.Text = lab.Observaciones;
                vLaboratorioAcciones.Content = lab.Accion;
            }
            catch (Exception ex)
            {

                MessageBox.Show("Error: " + ex.Message);
            }
        }

        private void rLaboratorioPlomo_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioPlomo.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioPlomo.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioPlomo.Text = "";
            }
        }

        private void rLaboratorioXileno_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioXileno.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioXileno.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioXileno.Text = "";
            }
        }

        private void rLaboratorioTolueno_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioTolueno.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioTolueno.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioTolueno.Text = "";
            }
        }

        private void rLaboratorioHb_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioHb.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioHb.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioHb.Text = "";
            }
        }

        private void rLaboratorioHto_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioHto.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioHto.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioHto.Text = "";
            }
        }

        private void rLaboratorioColesterol_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioColesterol.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioColesterol.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioColesterol.Text = "";
            }
        }

        private void rLaboratorioAcidoUrico_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioAcidoUrico.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioAcidoUrico.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioAcidoUrico.Text = "";
            }
        }

        private void rLaboratorioGlicemia_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioGlicemia.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioGlicemia.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioGlicemia.Text = "";
            }
        }

        private void rLaboratorioTrigliceridos_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioTrigliceridos.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioTrigliceridos.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioTrigliceridos.Text = "";
            }
        }

        private void rLaboratorioCreatinina_TextChanged(object sender, TextChangedEventArgs e)
        {
            float number;
            try
            {
                if (rLaboratorioCreatinina.Text != "")
                {
                    number = Convert.ToInt64(rLaboratorioCreatinina.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("El Campo debe Ser Numerico!");
                rLaboratorioCreatinina.Text = "";
            }
        }

        private void button17_Click(object sender, RoutedEventArgs e)
        {
            tabCOntrol.Visibility = Visibility.Visible;


            rRespiratorio.Visibility = Visibility.Hidden;
            eRespiratorio.Visibility = Visibility.Hidden;
            rRespiratorio2.Visibility = Visibility.Hidden;
            eRespiratorio2.Visibility = Visibility.Hidden;

            vAudiometrico.Visibility = Visibility.Hidden;
            rAudiometrico.Visibility = Visibility.Hidden;
            vAudiometrico2.Visibility = Visibility.Hidden;
            rAudiometrico2.Visibility = Visibility.Hidden;

            vOftalmologico.Visibility = Visibility.Hidden;
            rOftalmologico.Visibility = Visibility.Hidden;
            vOftalmologico2.Visibility = Visibility.Hidden;
            rOftalmologico2.Visibility = Visibility.Hidden;

            vLaboratorio.Visibility = Visibility.Hidden;
            vLaboratorio2.Visibility = Visibility.Hidden;
            rLaboratorio.Visibility = Visibility.Hidden;
            rLaboratorio2.Visibility = Visibility.Hidden;

            vCarnet.Visibility = Visibility.Visible;
            vCarnet2.Visibility = Visibility.Visible;
            rCarnet.Visibility = Visibility.Visible;
            rCarnet2.Visibility = Visibility.Visible;
        }

        private void button6_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                Carnet carnet = CarnetManager.BuscarAnalisisPorCi(Empleado.Ci);
                if (carnet == null)
                {
                    Carnet resp = new Carnet(0, Empleado.Ci, "", rCarnetAscaris.Text, rCarnetAmebas.Text, rCarnetGiardias.Text, rCarnetNematodos.Text, rCarnetTrematodos.Text, rCarnetTrichuris.Text, rCarnetOtros.Text, "", rCarnetAcciones.Text, rCarnetObservaciones.Text, fecha.Text);
                    CarnetManager.RegistrarAnalisis(resp);
                    MessageBox.Show("ANALISIS REGISTRADO!");


                }
                else
                {
                    Carnet resp = new Carnet(0, Empleado.Ci, "", rCarnetAscaris.Text, rCarnetAmebas.Text, rCarnetGiardias.Text, rCarnetNematodos.Text, rCarnetTrematodos.Text, rCarnetTrichuris.Text, rCarnetOtros.Text, "", rCarnetAcciones.Text, rCarnetObservaciones.Text, fecha.Text);
                    CarnetManager.EditarAnalisis(resp);
                    MessageBox.Show("ANALISIS MODIFICADO!");
                }



                vCarnetAscaris.Visibility = Visibility.Visible;
                vCarnetAmebas.Visibility = Visibility.Visible;
                vCarnetGiardias.Visibility = Visibility.Visible;
                vCarnetNematodos.Visibility = Visibility.Visible;
                vCarnetTrematodos.Visibility = Visibility.Visible;
                vCarnetTrichuris.Visibility = Visibility.Visible;
                vCarnetOtros.Visibility = Visibility.Visible;

                vCarnetObservaciones.Visibility = Visibility.Visible;
                vCarnetAcciones.Visibility = Visibility.Visible;

                Carnet carn = CarnetManager.BuscarAnalisisPorCi(Empleado.Ci);

                vCarnetAscaris.Content = carn.Ascaris;
                vCarnetAmebas.Content = carn.Amebas;
                vCarnetGiardias.Content = carn.Giardias;
                vCarnetNematodos.Content = carn.Nematodos;
                vCarnetTrematodos.Content = carn.Trematodos;
                vCarnetTrichuris.Content = carn.Trichuris;
                vCarnetOtros.Content = carn.OtrosParasitos;

                vCarnetObservaciones.Text = carn.Observaciones;
                vCarnetAcciones.Content = carn.Acciones;
            }
            catch (Exception ex)
            {

                MessageBox.Show("Error: " + ex.Message);
            }
        }
    }
}
